Skip to content

Reduce the codebase: comments, duplication, and single-use indirection - #36

Merged
FireSquid6 merged 6 commits into
mainfrom
code-reduction
Aug 3, 2026
Merged

Reduce the codebase: comments, duplication, and single-use indirection#36
FireSquid6 merged 6 commits into
mainfrom
code-reduction

Conversation

@FireSquid6

Copy link
Copy Markdown
Owner

A pure reduction pass over every workspace. No feature work, no bug fixes.

What changed

Commit Change Net
c1fae78 Tighten the comment policy to default-no-comment +18
4abd276 Strip comments the policy no longer allows −1,394
5bc3c0a Consolidate duplication, drop single-use indirection −69
f6b43e6 Extract the twin packages' shared cores +321
86cecc6 Map route errors once per plugin −217
3106995 Delete Store methods with no callers −12

Net −1,353 lines. Existing source shrank by ~1,900; the two new shared
packages add ~560 back, so the headline number understates the reduction.

751 tests pass, 0 fail, typecheck clean — verified after every step.
Baseline was 746: seven tests moved into fleet-cli-kit, five are new and
pin cli-bun's shared command base.

Reviewing this

4abd276 is comment-only. Filtering git diff -U0 to non-comment,
non-blank lines yields four items: three trailing-comment strips and one
catch { /* ignore */ } collapsing to catch {}. It can be read at a glance
or trusted wholesale; the later commits are where the substance is.

Eight ghost comments went with it — text describing code that no longer
exists, including a restoreAlt that is called leaveAlt, a header claiming
websockets were out of scope with attach 170 lines below, a doc calling the
already-shipped Eden client hypothetical, and a documented BRIDGE_URL env
var nothing reads.

Worth a closer look

86cecc6 removed 39 of 40 inlined mapError catches. Two keep their
inline catch deliberately: ship's GET /armory needs mapArmoryError, and
the terminal proxy's upstream.onmessage site closes sockets in the reverse
order of its siblings. The hook guards on instanceof against Elysia's own
error types — Elysia derives its error code from error.code, so an
unguarded hook renders validation failures as 500.

Differential probes over every route by error class confirm status,
content-type and body are byte-identical: 647/647 on the bridge, and on the
ship every reachable case.

f6b43e6 keeps ShellBackend separate per package. Sharing it would
have added an env parameter to tmux's public constructor, which never had
one.

Two things this pass found but did not fix

  • fagent/src/agent-ship.ts parses JSON outside its try and before the
    !response.ok check, so a 500 with a non-JSON body throws SyntaxError
    instead of the intended message.
  • Session.exists() and Tmux.hasSession() call tryRun, which never
    throws, so an unreachable tmux server reports "session does not exist".

Also noted: Eden Treaty's .data/.error resolve to any in this repo,
before and after this change. The route paths are typed; the payloads are
not.

🤖 Generated with Claude Code

FireSquid6 and others added 6 commits August 2, 2026 14:08
Drop the carve-outs for module/file-header doc blocks and section dividers,
and spell out the never-write list so the project policy matches the global
one instead of contradicting it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Remove module/file-header blocks, section dividers, restatement docstrings,
ceremonial @param/@returns templates, and narration across all ten code
workspaces. Trim the blocks whose buried rationale was worth keeping down to
that rationale.

Comments only: the sole non-comment changes are three trailing-comment strips
and one `catch { /* ignore */ }` collapsed to `catch {}`. Typecheck clean and
746 tests pass, unchanged from before.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Package-local reductions across seven workspaces:

- Store's ship and repo halves collapse onto one JsonCollection; the shared
  SerialQueue keeps both serialized against each other, and load() still
  commits both maps or neither.
- One SerialQueue, one isStrictDescendant, one armory record reader/writer,
  one GitHub header builder, one sha256 schema, one provider list.
- ReposRoute and ShipsRoute share a RegistryPage shell; five copies of the
  async-submit modal body become useSubmitAction.
- Row-shift, row-blank, and CSI/DCS sequence construction extracted in bun-vt.
- Un-export symbols with no external consumer; inline single-use aliases,
  pass-throughs, and injection points nothing supplies.

Restore four invariants that the comment pass deleted with their header
blocks, as one-line notes on the declarations that enforce them.

Typecheck clean and 746 tests pass, unchanged throughout.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
apps/cli and apps/fagent carried a copy-pasted client layer; git-bun and
tmux-bun a copy-pasted command base. Each pair now shares one package.

- fleet-cli-kit holds normalizeUrl, the bridge client, renderTable, and
  unwrap, which takes the program name as a parameter rather than baking in
  the message prefix. The seven normalizeUrl tests move with it, so fagent's
  previously untested copy is now covered.
- cli-bun holds RunResult, Backend, CliError, toInt, and an abstract
  CliCommand whose only abstract member is globalArgs(). GitError and
  TmuxError still extend it, so fleet-ship's catch-by-name keeps working.

ShellBackend stays separate per package: sharing it would have added an env
parameter to tmux's public constructor, which never had one.

Typecheck clean; 751 tests pass, up from 746 by the five new tests pinning
the shared command base.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The mapError catch tail was inlined 40 times across the two API layers.
Register it once per Elysia plugin instead and let handlers throw.

The hook guards on instanceof against Elysia's own error types: it derives
its error code from error.code, so an unguarded hook renders validation
failures as 500 and a code-string guard lets an ENOENT-tagged error escape
unmapped.

Two sites keep their inline catch deliberately. Ship's GET /armory needs
mapArmoryError, which maps ArmorySyncError to its own status rather than
500. The terminal proxy's upstream.onmessage binary site closes ws before
upstream, the reverse of its three siblings, and the ordering could not be
shown immaterial.

Also drop createApp's never-read config parameter, de-export
TERMINAL_INIT_TIMEOUT_MS, and name the terminal proxy's repeated socket
state and teardown.

Differential probes over every route by error class confirm status,
content-type, and body are byte-identical: 647/647 on the bridge, and on the
ship every reachable case, the 10 exceptions all requiring an async rejection
from agentStatus, which returns synchronously.

Typecheck clean; 751 tests pass.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
upsertShip, upsertRepo, and deleteShip have no caller anywhere in the repo.
Ship removal goes through replaceAllShips, and upsertShip was a pass-through
to createShip that nothing invoked.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@FireSquid6
FireSquid6 merged commit f6e5471 into main Aug 3, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant